package com.boat.ai.rag.Ingestion.strategy.impl;

import com.boat.ai.domain.enums.FileTypeEnum;
import com.boat.ai.rag.Ingestion.strategy.ParseStrategy;
import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.DocumentSplitter;
import dev.langchain4j.data.document.parser.TextDocumentParser;
import dev.langchain4j.data.document.splitter.DocumentSplitters;
import dev.langchain4j.data.segment.TextSegment;
import jakarta.enterprise.context.ApplicationScoped;

import java.io.InputStream;
import java.util.List;


@ApplicationScoped
public class TextParse implements ParseStrategy {

    @Override
    public FileTypeEnum type() {
        return FileTypeEnum.TEXT;
    }

    @Override
    public List<TextSegment> parse(InputStream inputStream) {
        TextDocumentParser textDocumentParser = new TextDocumentParser();
        Document document = textDocumentParser.parse(inputStream);
        DocumentSplitter splitter = DocumentSplitters.recursive(500, 50);
        return splitter.splitAll(List.of(document));
    }

}
